package demo1.web.servlet.userBuyapi;

import demo1.dao.Mapper.userBuyMapper;
import demo1.dao.sql.userBuysql;
import demo1.service.userBuyService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateAddress")
public class updateAddress extends HttpServlet {//修改地址
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        //获取更新的数据
        String usersAddress = req.getParameter("usersAddress");
        int addressID = Integer.parseInt(req.getParameter("addressID"));

        try {
            userBuyService update = new userBuyService();
            update.updateAddress(usersAddress,addressID);
            resp.sendRedirect("/logindemo2/showAddress");//重定向到展示地址的界面
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
